#! /usr/bin/perl -w
#------------------------------------------------
# Author:    kvkrishna
# Created:   Wed Aug  3 16:11:35 IST 2011
# File Name: Scroll
# USAGE: 
#       Scroll [-t "Text to Scroll"] [-l Line_number] [-n NoOfTimestoRepeat] 
#       [-s Speed(Char/Sec)] [-o OffSet] [-lo LeftOffSet] [-ro RightOffSet]
#  
#------------------------------------------------
chomp ($Lines   = `tput lines`) ;
chomp ($Cols    = `tput cols`)  ;
$SelLine        = $Lines ;
$Text           = "Sample Text  " ;
$Cnt            = 3 ;
$Speed          = 10 ;
$LO = $RO       = 0;
#------------------------------------------------
while ( scalar @ARGV > 0 ) {
        if      ( $ARGV[0] eq "-l"            ) { shift; $SelLine  = shift; next; }
        elsif   ( $ARGV[0] eq "-t"            ) { shift; $Text     = shift; next; }
        elsif   ( $ARGV[0] eq "-n"            ) { shift; $Cnt      = shift; next; }
        elsif   ( $ARGV[0] eq "-s"            ) { shift; $Speed    = shift; next; }
        elsif   ( $ARGV[0] eq "-o"            ) { shift; $RO = $LO = shift; next; }
        elsif   ( $ARGV[0] eq "-ro"           ) { shift; $RO       = shift; next; }
        elsif   ( $ARGV[0] eq "-lo"           ) { shift; $LO       = shift; next; }
        elsif   ( $ARGV[0] eq "-h"            ) { system "grep -m 1 -A 2 'USAGE' $0" ; exit ; } 
        else    { print "Invalid Option found...\nTry '-h' to know valid options\n"; exit  ;}
}
$LastCol = $Cols - $RO;
$SleepIntvel = (10 ** 6) / $Speed ;
system "tput sc ; tput civis ; tput cup $SelLine ; tput dl1 ; tput il1" ;
for ($i=0; $i<$Cnt; $i++) { 
        foreach (split //, "$Text") {
                system "tput cup $SelLine $LO ; tput dch 1" ;
                system "tput cup $SelLine $LastCol" ;
                print ;
                system "usleep $SleepIntvel";
        }
}
system "tput cup $SelLine $LO" ;
for ($j=0; $j<$LastCol - $LO; $j++) { 
        system "tput dch 1"; 
        system "usleep $SleepIntvel";
}
system "tput cnorm ; tput rc";
